<template>
    <el-card shadow="never" class="aui-card--fill">
      <div class="mod-sys__dict">
        <el-form :inline="true" :model="dataForm"  @keydown.enter.native.prevent="getDataList()">
          <!-- <el-form-item>
            <el-input v-model="dataForm.dictValue" placeholder="字典值" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-input v-model="dataForm.dictLabel" placeholder="字典标签" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <el-button @click="getDataList()">查询</el-button>
          </el-form-item> -->
          <el-form-item>
            <el-button  type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0" >批量删除</el-button>
            <el-button  type="success" @click=getDataList() >刷新</el-button>
            <!-- <el-button v-if="$hasPermission('sys:dict:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button> -->
          </el-form-item>
        </el-form>
        <el-table
          v-loading="dataListLoading"
          :data="dataList"
          border
          @selection-change="dataListSelectionChangeHandle"
          
          style="width: 100%;">
          <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
          <el-table-column prop="recordsId" label="指导编号" header-align="center" align="center"></el-table-column>
          <el-table-column prop="name" label="教师姓名" header-align="center" align="center"></el-table-column>
          <!-- <el-table-column prop="sort" label="排序" sortable header-align="center" align="center"></el-table-column> -->
          <el-table-column prop="stuSituation" label="学生学习情况" header-align="center" align="center"></el-table-column>
          <el-table-column prop="reImfor" label="指导内容" sortable header-align="center" align="center" width="180"></el-table-column>
          <el-table-column  label="操作" fixed="right" header-align="center" align="center" width="150" >
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="deleteHandle(scope.row.recordsId)">删除</el-button>
              <el-button type="text" size="small" @click="changeHandle(scope.row)">修改</el-button>
              <!-- <el-button v-if="$hasPermission('sys:dict:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
              <el-button v-if="$hasPermission('sys:dict:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
      </div>
    </el-card>
  </template>
  
  <script>
  import servicesApi from '@/services/servicesApi'
  import AddOrUpdate from '@/views/Teacher/submit-ttdeguidance'
  export default {
    data() {
      return {
        // mixinViewModuleOptions: {
        //   createdIsNeed: false,
        //   getDataListURL: '/sys/dict/data/page',
        //   getDataListIsPage: true,
        //   deleteURL: '/sys/dict/data',
        //   deleteIsBatch: true
        // },
        dataForm: {
          dictTypeId: '0',
          dictLabel: '',
          dictValue: '',
          susername: ''
        },
        dataFForm: {

        },
        dataList: [
        ],               // 数据列表
        order: '',                  // 排序，asc／desc
        orderField: '',             // 排序，字段
        page: 1,                    // 当前页码
        limit: 10,                  // 每页数
        total: 0,                   // 总条数
        dataListLoading: false,     // 数据列表，loading状态
        dataListSelections: [],     // 数据列表，多选项
        addOrUpdateVisible: false,   // 新增／更新，弹窗visible
        deleteList: {
                list: []
             },
      }
    },
    components: {
      AddOrUpdate
    },
    created() {
      this.dataFForm.susername = this.$route.params.dictTypeId
      // console.log('动态添加路由传入参数dictTypeId=%s', this.dataForm.susername)
      this.getDataList()
    },
    activated() {
      this.getDataList()
    },
    methods: {
        changeHandle(row) {
            this.addOrUpdateVisible = true
        this.$nextTick(() => {
          // this.$refs.addOrUpdate.dataForm.id = id
          this.$refs['addOrUpdate'].init(row)
        })
    },
      getDataList() {
        // this.dataListLoading = true
        // this.total = this.dataList.length
        // this.dataListLoading = false
  
        this.dataListLoading = true
        let pageInfo = {
          current: this.page,
          size: this.limit,
          name: this.dataFForm.susername,
        }
        servicesApi.getTrguidance(pageInfo).then(res => {
          // console.log(res.data)
          let code = res.data.code
          let data = res.data.data
          if (code === 200) {
            this.dataList = data.records
            this.total = data.total
          } else {
            this.dataList = []
            this.total = 0
          }
          this.dataListLoading = false
        })
      },
      // 新增 / 修改
      addOrUpdateHandle(id) {
        // console.log('新增/修改---id==%s,dictTypeId=%s', id, this.dataForm.dictTypeId)
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          // this.$refs.addOrUpdate.dataForm.id = id
          // this.$refs.addOrUpdate.dataForm.dictTypeId = this.dataForm.dictTypeId
          this.$refs.addOrUpdate.init(id, this.dataForm.dictTypeId)
        })
      },
      // 删除
      deleteHandle(id) {
  
        let dictItemIds = id ? [id] : this.dataListSelections.map(item => {
          return item.recordsId
        })
        this.deleteList.list = dictItemIds
        // console.log(dictItemIds)
  
          servicesApi.delTTguidance(this.deleteList).then(res => {
            if (res.data.code !== 200) {
              return this.$message.error(res.data.msg)
            }
            this.$message({
              message: '删除成功',
              type: 'success',
              duration: 1000,
              onClose: () => {
                this.getDataList()
              }
            })
          })
      },
      // 多选
      dataListSelectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 排序
      dataListSortChangeHandle(data) {
        // if (!data.order || !data.prop) {
        //   this.order = ''
        //   this.orderField = ''
        //   return false
        // }
        // this.order = data.order.replace(/ending$/, '')
        // this.orderField = data.prop.replace(/([A-Z])/g, '_$1').toLowerCase()
        // this.getDataList()
      },
      // 分页, 每页条数
      pageSizeChangeHandle(val) {
        this.page = 1
        this.limit = val
        this.getDataList()
      },
      // 分页, 当前页
      pageCurrentChangeHandle(val) {
        this.page = val
        this.getDataList()
      },
      // 关闭当前窗口
      closeCurrentTab(data) {
        let tabName = this.$store.state.contentTabsActiveName
        this.$store.state.contentTabs = this.$store.state.contentTabs.filter(item => item.name !== tabName)
        if (this.$store.state.contentTabs.length <= 0) {
          this.$store.state.sidebarMenuActiveName = this.$store.state.contentTabsActiveName = 'home'
          return false
        }
        if (tabName === this.$store.state.contentTabsActiveName) {
          this.$router.push({ name: this.$store.state.contentTabs[this.$store.state.contentTabs.length - 1].name })
        }
      },
      
    }
  }
  </script>
  